package com.lmonkey.servlet.cart;

import com.lmonkey.servic.CARTDao;
import com.lmonkey.servic.ORDERDao;
import com.lmonkey.shop.CART;
import com.lmonkey.shop.ORDER;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet("/admin/admin_cartselect")
public class AdminCartSelect extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置字符集
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        //获取数据
        int cpage = 1;
        int count = 5;
        String cp = request.getParameter("cp");
        String keyword = request.getParameter("keywords");
        if (cp != null){
            cpage = Integer.parseInt(cp);
        }

        int arr[] = ORDERDao.titlepage1(count,keyword);

        ArrayList<ORDER> clist = ORDERDao.selectAll1(cpage,count,keyword);

        request.setAttribute("cpage",cpage);
        request.setAttribute("clist",clist);
        request.setAttribute("count",arr[1]);
        request.setAttribute("total",arr[0]);

        if (keyword != null){
            request.setAttribute("searchParams","&keywords="+keyword);
        }

        request.getRequestDispatcher("admin_cart.jsp").forward(request,response);
    }
}
